﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

using WeChatDemo.Utils;
using WeChatDemo.Models.Photo;

namespace WeChatDemo.DataProvider.Photo
{
    public class DAOPhotoItem : DAOBase
    {
        public static bool Add(PhotoItem model)
        {
            bool flag = false;

            string _sqlString = $"INSERT INTO [PhotoItem](ID, Title, ImageUrl, UserID) VALUES('{model.ID}','{model.Title}', '{model.ImageUrl}', '{model.UserID}')";

            flag = SqlHelper.ExecuteNonQuery(_connectionString, CommandType.Text, _sqlString) == 0 ? false : true;

            return flag;
        }

        public static bool Update(PhotoItem model)
        {
            bool flag = false;

            string _sqlString = $"UPDATE [PhotoItem] SET Title = '{model.Title}', ImageUrl = '{model.ImageUrl}' WHERE ID = '{model.ID}'";

            flag = SqlHelper.ExecuteNonQuery(_connectionString, CommandType.Text, _sqlString) == 0 ? false : true;

            return flag;
        }

        public static bool Delete(Guid id)
        {
            bool flag = false;

            string _sqlString = $"DELETE FROM [PhotoItem] WHERE ID = '{id}'";

            flag = SqlHelper.ExecuteNonQuery(_connectionString, CommandType.Text, _sqlString) == 0 ? false : true;

            return flag;
        }
    }
}